package com.xbongbong.sso.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 授权类型枚举
 */
@Getter
public enum StepTypeEnum {
    /**
     *
     */
    AUTH_CODE(1,"Auth Code"),
    ACCESS_TOKEN(2,"Access Token"),
    ID_AUTH(3,"Identity Authentication"),
//    LOGOUT_SETTINGS(4,"Logout Settings"),
    UNKNOWN(-1,"unknown"),
    ;

    private Integer code;

    private String name;

    StepTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据code获取枚举
     * @return
     */
    public static StepTypeEnum getByCode(Integer code) {
        if (code == null) {
            return UNKNOWN;
        }
        for (StepTypeEnum cache : values()) {
            if (Objects.equals(cache.getCode(), code)) {
                return cache;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取包含的所有步骤
     * @return
     */
    public static List<StepTypeEnum> getAll(){
        List<StepTypeEnum> list = Arrays.asList(AUTH_CODE, ACCESS_TOKEN, ID_AUTH);
        return list;
    }
}
